package com.lineage.server.model;

import com.add.En_count;
import com.lineage.data.ItemClass;
import com.lineage.data.event.En_lv;
import com.lineage.data.item_armor.set.ArmorSet;
import com.lineage.server.datatables.ItemSpecialAttributeTable;
import com.lineage.server.datatables.ItemTimeTable;
import com.lineage.server.datatables.PowerItemTable;
import com.lineage.server.datatables.lock.CharItemsTimeReading;
import com.lineage.server.datatables.lock.CharSkillReading;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_Ability;
import com.lineage.server.serverpackets.S_AddSkill;
import com.lineage.server.serverpackets.S_DelSkill;
import com.lineage.server.serverpackets.S_Invis;
import com.lineage.server.serverpackets.S_ItemName;
import com.lineage.server.serverpackets.S_RemoveObject;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.S_SkillBrave;
import com.lineage.server.serverpackets.S_SkillHaste;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Item;
import com.lineage.server.templates.L1ItemPower_name;
import com.lineage.server.templates.L1ItemSpecialAttribute;
import com.lineage.server.templates.L1ItemSpecialAttributeChar;
import com.lineage.william.L1WilliamEnchantAccessory;
import com.lineage.william.L1WilliamEnchantOrginal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1EquipmentSlot {
  public static final Log _log = LogFactory.getLog(L1EquipmentSlot.class);
  
  private final PowerItemTable _l1power;
  
  private final L1PcInstance _owner;
  
  private final ArrayList<ArmorSet> _currentArmorSet;
  
  private final ArrayList<L1ItemInstance> _armors;
  
  private L1ItemInstance _weapon;
  
  public L1EquipmentSlot(L1PcInstance owner) {
    this._owner = owner;
    this._armors = new ArrayList<>();
    this._currentArmorSet = new ArrayList<>();
    this._l1power = PowerItemTable.get();
  }
  
  public L1ItemInstance getWeapon() {
    return this._weapon;
  }
  
  private void setWeapon(L1ItemInstance weapon) {
    int hppotion = 0;
    this._owner.setWeapon(weapon);
    this._owner.setCurrentWeapon(weapon.getItem().getType1());
    weapon.startEquipmentTimer(this._owner);
    this._weapon = weapon;
    if (this._weapon.getItem().getMagicDmgModifier() != 0)
      this._owner.add_magic_modifier_dmg(this._weapon.getItem().getMagicDmgModifier()); 
    if (this._weapon.getItem().getPVPdmg() != 0)
      this._owner.addPVPdmg(this._weapon.getItem().getPVPdmg()); 
    if (this._weapon.getItem().getPVPdmgReduction() != 0)
      this._owner.addPVPdmgReduction(this._weapon.getItem().getPVPdmgReduction()); 
    if (this._weapon.getItem().getpenetrate() == 1)
      this._owner.setpenetrate(1); 
    if (this._weapon.getItem().getNoweaponRedmg() > 0)
      this._owner.setNoweaponRedmg(this._weapon.getItem().getNoweaponRedmg()); 
    if (this._weapon.getItem().getaddStunLevel() > 0)
      this._owner.setaddStunLevel(this._weapon.getItem().getaddStunLevel()); 
  }
  
  public ArrayList<L1ItemInstance> getArmors() {
    return this._armors;
  }
  
  private void removeWeapon(L1ItemInstance weapon) {
    this._owner.setWeapon(null);
    this._owner.setCurrentWeapon(0);
    weapon.stopEquipmentTimer(this._owner);
    if (this._weapon.getItem().getMagicDmgModifier() != 0)
      this._owner.add_magic_modifier_dmg(-this._weapon.getItem().getMagicDmgModifier()); 
    if (this._weapon.getItem().getPVPdmg() != 0)
      this._owner.addPVPdmg(-this._weapon.getItem().getPVPdmg()); 
    if (this._weapon.getItem().getPVPdmgReduction() != 0)
      this._owner.addPVPdmgReduction(-this._weapon.getItem().getPVPdmgReduction()); 
    if (this._weapon.getItem().getpenetrate() == 1)
      this._owner.setpenetrate(0); 
    if (this._weapon.getItem().getNoweaponRedmg() > 0)
      this._owner.setNoweaponRedmg(0); 
    if (this._weapon.getItem().getaddStunLevel() > 0)
      this._owner.setaddStunLevel(-this._weapon.getItem().getaddStunLevel()); 
    this._weapon = null;
    if (this._owner.hasSkillEffect(91))
      this._owner.removeSkillEffect(91); 
  }
  
  private void setArmor(L1ItemInstance armor) {
    L1Item item = armor.getItem();
    int itemId = armor.getItem().getItemId();
    int use_type = armor.getItem().getUseType();
    switch (use_type) {
      case 2:
      case 18:
      case 19:
      case 20:
      case 21:
      case 22:
      case 25:
      case 47:
        this._owner.addAc(item.get_ac() - armor.getEnchantLevel() - armor.getAcByMagic() - armor.getItemAc());
        break;
      case 23:
      case 24:
      case 37:
      case 40:
        if (item.get_ac() != 0)
          this._owner.addAc(item.get_ac()); 
        break;
      case 43:
      case 44:
      case 45:
      case 48:
      case 49:
      case 51:
        if (item.get_ac() != 0)
          this._owner.addAc(item.get_ac() - armor.getItemAc()); 
        break;
    } 
    if (En_lv.START && (armor.getItem().getUseType() == 2 || armor.getItem().getUseType() == 22 || 
      armor.getItem().getUseType() == 21 || armor.getItem().getUseType() == 19 || 
      armor.getItem().getUseType() == 18 || armor.getItem().getUseType() == 20)) {
      En_count.forIntensifyArmor1(this._owner, armor);
      int en = armor.getEnchantLevel() - item.get_safeenchant();
      if (en > 0)
        this._owner.setArmorCount1(this._owner.getArmorCount1() + en); 
      En_count.forIntensifyArmor(this._owner, armor);
    } 
    set_time_item(armor);
    L1WilliamEnchantAccessory.getAddArmorOrginal(this._owner, armor);
    this._owner.add_up_hp_potion(item.get_up_hp_potion());
    this._owner.add_uhp_number(item.get_uhp_number());
    this._owner.addDamageReductionByArmor(armor.getDamageReduction() + armor.getItemReductionDmg());
    this._owner.addWeightReduction(item.getWeightReduction());
    int hit = armor.getHitModifierByArmor() + armor.getItemHit();
    int dmg = item.getDmgModifierByArmor() + armor.getItemAttack();
    this._owner.addHitModifierByArmor(hit);
    this._owner.addDmgModifierByArmor(dmg);
    this._owner.addBowHitModifierByArmor(item.getBowHitModifierByArmor() + armor.getItemHit());
    this._owner.addBowDmgModifierByArmor(item.getBowDmgModifierByArmor() + armor.getItemAttack());
    this._owner.addOriginalMagicHit(item.getMagicHitModifierByArmor());
    int addFire = item.get_defense_fire();
    this._owner.addFire(addFire);
    int addWater = item.get_defense_water();
    this._owner.addWater(addWater);
    int addWind = item.get_defense_wind();
    this._owner.addWind(addWind);
    int addEarth = item.get_defense_earth();
    this._owner.addEarth(addEarth);
    int add_regist_freeze = item.get_regist_freeze();
    this._owner.add_regist_freeze(add_regist_freeze);
    int addRegistStone = item.get_regist_stone();
    this._owner.addRegistStone(addRegistStone);
    int addRegistSleep = item.get_regist_sleep();
    this._owner.addRegistSleep(addRegistSleep);
    int addRegistBlind = item.get_regist_blind();
    this._owner.addRegistBlind(addRegistBlind);
    int addRegistStun = item.get_regist_stun();
    this._owner.addRegistStun(addRegistStun);
    int addRegistSustain = item.get_regist_sustain();
    this._owner.addRegistSustain(addRegistSustain);
    this._armors.add(armor);
    if (armor.getItem().getPVPdmg() != 0)
      this._owner.addPVPdmg(armor.getItem().getPVPdmg()); 
    if (armor.getItem().getPVPdmgReduction() != 0)
      this._owner.addPVPdmgReduction(armor.getItem().getPVPdmgReduction()); 
    if (armor.getItemhppotion() > 0)
      this._owner.add_potion_heal(armor.getItemhppotion()); 
    Iterator<Integer> iterator = ArmorSet.getAllSet().keySet().iterator();
    while (iterator.hasNext()) {
      Integer key = iterator.next();
      ArmorSet armorSet = (ArmorSet)ArmorSet.getAllSet().get(key);
      if (armorSet.isPartOfSet(itemId) && armorSet.isValid(this._owner)) {
        if (armor.getItem().getUseType() == 23) {
          if (armorSet.isEquippedRingOfArmorSet(this._owner))
            continue; 
          armorSet.giveEffect(this._owner);
          this._currentArmorSet.add(armorSet);
          this._owner.getInventory().setPartMode(armorSet, true);
          continue;
        } 
        this._owner.setarmor_setgive(true);
        armorSet.giveEffect(this._owner);
        this._currentArmorSet.add(armorSet);
        this._owner.getInventory().setPartMode(armorSet, true);
      } 
    } 
    armor.startEquipmentTimer(this._owner);
  }
  
  private void set_time_item(L1ItemInstance item) {
    if (item.get_time() == null) {
      int[] date = null;
      if (ItemTimeTable.TIME.get(Integer.valueOf(item.getItemId())) != null)
        date = (int[])ItemTimeTable.TIME.get(Integer.valueOf(item.getItemId())); 
      if (date != null) {
        Calendar cal = Calendar.getInstance();
        if (date[0] != 0)
          cal.add(5, date[0]); 
        if (date[1] != 0)
          cal.add(11, date[1]); 
        if (date[2] != 0)
          cal.add(12, date[2]); 
        Timestamp ts = new Timestamp(cal.getTimeInMillis());
        item.set_time(ts);
        CharItemsTimeReading.get().addTime(item.getId(), ts);
        this._owner.sendPackets((ServerBasePacket)new S_ItemName(item));
      } 
    } 
  }
  
  private void removeArmor(L1ItemInstance armor) {
    L1Item item = armor.getItem();
    int itemId = armor.getItem().getItemId();
    int use_type = armor.getItem().getUseType();
    switch (use_type) {
      case 2:
      case 18:
      case 19:
      case 20:
      case 21:
      case 22:
      case 25:
      case 47:
        this._owner.addAc(-(item.get_ac() - armor.getEnchantLevel() - armor.getAcByMagic() - armor.getItemAc()));
        break;
      case 23:
      case 24:
      case 37:
      case 40:
        if (item.get_ac() != 0)
          this._owner.addAc(-item.get_ac()); 
        break;
      case 43:
      case 44:
      case 45:
      case 48:
      case 49:
      case 51:
        if (item.get_ac() != 0)
          this._owner.addAc(-item.get_ac()); 
        break;
    } 
    if (En_lv.START && (armor.getItem().getUseType() == 2 || armor.getItem().getUseType() == 22 || 
      armor.getItem().getUseType() == 21 || armor.getItem().getUseType() == 19 || 
      armor.getItem().getUseType() == 18 || armor.getItem().getUseType() == 20)) {
      En_count.forIntensifyArmor1(this._owner, armor);
      int en = armor.getEnchantLevel() - item.get_safeenchant();
      if (en > 0)
        this._owner.setArmorCount1(this._owner.getArmorCount1() - en); 
      if (this._owner.getArmorCount1() > 0)
        En_count.forIntensifyArmor(this._owner, armor); 
    } 
    L1WilliamEnchantAccessory.getReductionArmorOrginal(this._owner, armor);
    this._owner.add_up_hp_potion(-item.get_up_hp_potion());
    this._owner.add_uhp_number(-item.get_uhp_number());
    this._owner.addDamageReductionByArmor(-armor.getDamageReduction() - armor.getItemReductionDmg());
    this._owner.addWeightReduction(-item.getWeightReduction());
    int hit = armor.getHitModifierByArmor();
    int dmg = item.getDmgModifierByArmor();
    this._owner.addHitModifierByArmor(-hit - armor.getItemHit());
    this._owner.addDmgModifierByArmor(-dmg - armor.getItemAttack());
    this._owner.addBowHitModifierByArmor(-item.getBowHitModifierByArmor() - armor.getItemHit());
    this._owner.addBowDmgModifierByArmor(-item.getBowDmgModifierByArmor() - armor.getItemAttack());
    this._owner.addOriginalMagicHit(-item.getMagicHitModifierByArmor());
    int addFire = item.get_defense_fire();
    this._owner.addFire(-addFire);
    int addWater = item.get_defense_water();
    this._owner.addWater(-addWater);
    int addWind = item.get_defense_wind();
    this._owner.addWind(-addWind);
    int addEarth = item.get_defense_earth();
    this._owner.addEarth(-addEarth);
    int add_regist_freeze = item.get_regist_freeze();
    this._owner.add_regist_freeze(-add_regist_freeze);
    int addRegistStone = item.get_regist_stone();
    this._owner.addRegistStone(-addRegistStone);
    int addRegistSleep = item.get_regist_sleep();
    this._owner.addRegistSleep(-addRegistSleep);
    int addRegistBlind = item.get_regist_blind();
    this._owner.addRegistBlind(-addRegistBlind);
    int addRegistStun = item.get_regist_stun();
    this._owner.addRegistStun(-addRegistStun);
    int addRegistSustain = item.get_regist_sustain();
    this._owner.addRegistSustain(-addRegistSustain);
    Iterator<Integer> iterator = ArmorSet.getAllSet().keySet().iterator();
    while (iterator.hasNext()) {
      Integer key = iterator.next();
      ArmorSet armorSet = (ArmorSet)ArmorSet.getAllSet().get(key);
      if (armorSet.isPartOfSet(itemId) && this._currentArmorSet.contains(armorSet) && 
        !armorSet.isValid(this._owner)) {
        this._owner.setarmor_setgive(false);
        armorSet.cancelEffect(this._owner);
        this._currentArmorSet.remove(armorSet);
        this._owner.getInventory().setPartMode(armorSet, false);
      } 
    } 
    armor.stopEquipmentTimer(this._owner);
    this._armors.remove(armor);
    if (armor.getItem().getPVPdmg() != 0)
      this._owner.addPVPdmg(-armor.getItem().getPVPdmg()); 
    if (armor.getItem().getPVPdmgReduction() != 0)
      this._owner.addPVPdmgReduction(-armor.getItem().getPVPdmgReduction()); 
    int hppontion = armor.getItemhppotion();
    if (hppontion > 0)
      this._owner.add_potion_heal(-hppontion); 
  }
  
  public void set(L1ItemInstance eq) {
    L1Item item = eq.getItem();
    if (item.getType2() == 0)
      return; 
    int attr_str = 0;
    int attr_con = 0;
    int attr_dex = 0;
    int attr_int = 0;
    int attr_wis = 0;
    int attr_cha = 0;
    int attr_hp = 0;
    int attr_mp = 0;
    int attr_sp = 0;
    int attr_def = 0;
    int pvp_dmg = 0;
    int pvp_redmg = 0;
    int potion_heal = 0;
    int attr_物理格档 = 0;
    int attr_魔法格档 = 0;
    int attr_hpr = 0;
    int attr_mpr = 0;
    int attr_dmgR = 0;
    L1ItemSpecialAttributeChar attr_char = eq.get_ItemAttrName();
    if (attr_char != null) {
      L1ItemSpecialAttribute attr = ItemSpecialAttributeTable.get().getAttrId(attr_char.get_attr_id());
      attr_str = attr.get_add_str();
      attr_con = attr.get_add_con();
      attr_dex = attr.get_add_dex();
      attr_int = attr.get_add_int();
      attr_wis = attr.get_add_wis();
      attr_cha = attr.get_add_cha();
      attr_hp = attr.get_add_hp();
      attr_mp = attr.get_add_mp();
      attr_sp = attr.get_add_sp();
      attr_def = attr.get_add_m_def();
      pvp_dmg = attr.get_add_pvp_dmg();
      pvp_redmg = attr.get_add_pvp_redmg();
      potion_heal = attr.get_add_potion_heal();
      attr_物理格档 = attr.get物理格档();
      attr_魔法格档 = attr.get魔法格档();
      attr_hpr = attr.get_add_hpr();
      attr_mpr = attr.get_add_mpr();
      attr_dmgR = attr.get_add_dmgR();
    } 
    L1WilliamEnchantOrginal.getAddArmorOrginal(this._owner, eq);
    int addhp = item.get_addhp() + eq.getItemHp() + attr_hp;
    int addmp = item.get_addmp() + eq.getItemMp() + attr_mp;
    int get_addstr = item.get_addstr() + eq.getItemStr() + attr_str;
    int get_adddex = item.get_adddex() + eq.getItemDex() + attr_dex;
    int get_addcon = item.get_addcon() + eq.getItemCon() + attr_con;
    int get_addwis = item.get_addwis() + eq.getItemWis() + attr_wis;
    int get_addint = item.get_addint() + eq.getItemInt() + attr_int;
    int get_addcha = item.get_addcha() + eq.getItemCha() + attr_cha;
    int addMr = 0;
    int addSp = 0 + attr_sp;
    int addAc = 0;
    int addHpr = 0;
    int addMpr = 0;
    int addDmgModifier = 0;
    int addHitModifier = 0;
    int bow_hit_modifier = 0;
    int bow_dmg_modifier = 0;
    if (eq.get_power_name() != null) {
      L1ItemPower_name power = eq.get_power_name();
      addAc += (this._l1power.getItem(power.get_hole_1())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_1())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_1())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_1())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_1())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_1())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_1())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_1())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_1())).addMaxMP;
      addDmgModifier += (this._l1power.getItem(power.get_hole_1())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_1())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_1())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_1())).add_sp;
      addHpr += (this._l1power.getItem(power.get_hole_1())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_1())).add_mpr;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_1())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_1())).bow_dmg_modifier;
      addAc += (this._l1power.getItem(power.get_hole_2())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_2())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_2())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_2())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_2())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_2())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_2())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_2())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_2())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_2())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_2())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_2())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_2())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_2())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_2())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_2())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_2())).bow_dmg_modifier;
      addAc += (this._l1power.getItem(power.get_hole_3())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_3())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_3())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_3())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_3())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_3())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_3())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_3())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_3())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_3())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_3())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_3())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_3())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_3())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_3())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_3())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_3())).bow_dmg_modifier;
      addAc += (this._l1power.getItem(power.get_hole_4())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_4())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_4())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_4())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_4())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_4())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_4())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_4())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_4())).addMaxMP;
      addDmgModifier += (this._l1power.getItem(power.get_hole_4())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_4())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_4())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_4())).add_sp;
      addHpr += (this._l1power.getItem(power.get_hole_4())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_4())).add_mpr;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_4())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_4())).bow_dmg_modifier;
      addAc += (this._l1power.getItem(power.get_hole_5())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_5())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_5())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_5())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_5())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_5())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_5())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_5())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_5())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_5())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_5())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_5())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_5())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_5())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_5())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_5())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_5())).bow_dmg_modifier;
    } 
    if (pvp_dmg != 0)
      this._owner.addPVPdmg(pvp_dmg); 
    if (pvp_redmg != 0)
      this._owner.addPVPdmgReduction(pvp_redmg); 
    if (potion_heal != 0)
      this._owner.addattr_potion_heal(potion_heal); 
    if (attr_物理格档 != 0)
      this._owner.addattr_物理格档(attr_物理格档); 
    if (attr_魔法格档 != 0)
      this._owner.addattr_魔法格档(attr_魔法格档); 
    if (attr_hpr != 0)
      this._owner.addHpr(attr_hpr); 
    if (attr_mpr != 0)
      this._owner.addMpr(attr_mpr); 
    if (attr_dmgR != 0)
      this._owner.addother_ReductionDmg(attr_dmgR); 
    if (addhp != 0)
      this._owner.addMaxHp(addhp); 
    if (addmp != 0)
      this._owner.addMaxMp(addmp); 
    this._owner.addAc(-addAc);
    this._owner.addBowDmgup(bow_dmg_modifier);
    this._owner.addBowHitup(bow_hit_modifier);
    this._owner.addDmgup(addDmgModifier);
    this._owner.addHitup(addHitModifier);
    this._owner.addStr(get_addstr);
    this._owner.addDex(get_adddex);
    this._owner.addCon(get_addcon);
    this._owner.addWis(get_addwis);
    if (get_addwis != 0)
      this._owner.resetBaseMr(); 
    this._owner.addInt(get_addint);
    this._owner.addCha(get_addcha);
    addMr = eq.getMr() + eq.getItemMr() + attr_def;
    if (eq.getName().equals("精灵盾牌") && this._owner.isElf())
      addMr += 5; 
    if (addMr != 0) {
      this._owner.addMr(addMr);
      this._owner.sendPackets((ServerBasePacket)new S_SPMR(this._owner));
    } 
    if (addHpr != 0)
      this._owner.addHpr(addHpr); 
    if (addMpr != 0)
      this._owner.addMpr(addMpr); 
    addSp += eq.getSp() + eq.getItemSp();
    if (addSp != 0) {
      this._owner.addSp(addSp);
      this._owner.sendPackets((ServerBasePacket)new S_SPMR(this._owner));
    } 
    if (eq.getItemistSustain() != 0)
      this._owner.addRegistSustain(eq.getItemistSustain()); 
    if (eq.getItemistStun() != 0)
      this._owner.addRegistStun(eq.getItemistStun()); 
    if (eq.getItemistStone() != 0)
      this._owner.addRegistStone(eq.getItemistStone()); 
    if (eq.getItemistSleep() != 0)
      this._owner.addRegistSleep(eq.getItemistSleep()); 
    if (eq.getItemistFreeze() != 0)
      this._owner.add_regist_freeze(eq.getItemistFreeze()); 
    if (eq.getItemistBlind() != 0)
      this._owner.addRegistBlind(eq.getItemistBlind()); 
    boolean isHasteItem = item.isHasteItem();
    if (isHasteItem) {
      this._owner.addHasteItemEquipped(1);
      this._owner.removeHasteSkillEffect();
      if (this._owner.getMoveSpeed() != 1) {
        this._owner.setMoveSpeed(1);
        this._owner.sendPackets((ServerBasePacket)new S_SkillHaste(this._owner.getId(), 1, -1));
        this._owner.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(this._owner.getId(), 1, 0));
      } 
    } 
    switch (item.getType2()) {
      case 1:
        setWeapon(eq);
        ItemClass.get().item_weapon(true, this._owner, eq);
        break;
      case 2:
        setArmor(eq);
        setMagic(eq);
        ItemClass.get().item_armor(true, this._owner, eq);
        break;
    } 
    this._owner.setExpPoint(this._owner.getExpPoint() + item.getExpPoint());
  }
  
  public void remove(L1ItemInstance eq) {
    L1Item item = eq.getItem();
    if (item.getType2() == 0)
      return; 
    int attr_str = 0;
    int attr_con = 0;
    int attr_dex = 0;
    int attr_int = 0;
    int attr_wis = 0;
    int attr_cha = 0;
    int attr_hp = 0;
    int attr_mp = 0;
    int attr_sp = 0;
    int attr_def = 0;
    int pvp_dmg = 0;
    int pvp_redmg = 0;
    int potion_heal = 0;
    int attr_物理格档 = 0;
    int attr_魔法格档 = 0;
    int attr_hpr = 0;
    int attr_mpr = 0;
    int attr_dmgR = 0;
    L1ItemSpecialAttributeChar attr_char = eq.get_ItemAttrName();
    if (attr_char != null) {
      L1ItemSpecialAttribute attr = ItemSpecialAttributeTable.get().getAttrId(attr_char.get_attr_id());
      attr_str = attr.get_add_str();
      attr_con = attr.get_add_con();
      attr_dex = attr.get_add_dex();
      attr_int = attr.get_add_int();
      attr_wis = attr.get_add_wis();
      attr_cha = attr.get_add_cha();
      attr_hp = attr.get_add_hp();
      attr_mp = attr.get_add_mp();
      attr_sp = attr.get_add_sp();
      attr_def = attr.get_add_m_def();
      pvp_dmg = attr.get_add_pvp_dmg();
      pvp_redmg = attr.get_add_pvp_redmg();
      potion_heal = attr.get_add_potion_heal();
      attr_物理格档 = attr.get物理格档();
      attr_魔法格档 = attr.get魔法格档();
      attr_hpr = attr.get_add_hpr();
      attr_mpr = attr.get_add_mpr();
      attr_dmgR = attr.get_add_dmgR();
    } 
    L1WilliamEnchantOrginal.getReductionArmorOrginal(this._owner, eq);
    int addhp = item.get_addhp() + eq.getItemHp() + attr_hp;
    int addmp = item.get_addmp() + eq.getItemMp() + attr_mp;
    int get_addstr = item.get_addstr() + eq.getItemStr() + attr_str;
    int get_adddex = item.get_adddex() + eq.getItemDex() + attr_dex;
    int get_addcon = item.get_addcon() + eq.getItemCon() + attr_con;
    int get_addwis = item.get_addwis() + eq.getItemWis() + attr_wis;
    int get_addint = item.get_addint() + eq.getItemInt() + attr_int;
    int get_addcha = item.get_addcha() + eq.getItemCha() + attr_cha;
    int addMr = 0;
    int addAc = 0;
    int addSp = 0 + attr_sp;
    int addHpr = 0;
    int addMpr = 0;
    int addDmgModifier = 0;
    int addHitModifier = 0;
    int bow_hit_modifier = 0;
    int bow_dmg_modifier = 0;
    if (eq.get_power_name() != null) {
      L1ItemPower_name power = eq.get_power_name();
      addAc -= -(this._l1power.getItem(power.get_hole_1())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_1())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_1())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_1())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_1())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_1())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_1())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_1())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_1())).addMaxMP;
      addDmgModifier += (this._l1power.getItem(power.get_hole_1())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_1())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_1())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_1())).add_sp;
      addHpr += (this._l1power.getItem(power.get_hole_1())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_1())).add_mpr;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_1())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_1())).bow_dmg_modifier;
      addAc -= -(this._l1power.getItem(power.get_hole_2())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_2())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_2())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_2())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_2())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_2())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_2())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_2())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_2())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_2())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_2())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_2())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_2())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_2())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_2())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_2())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_2())).bow_dmg_modifier;
      addAc -= -(this._l1power.getItem(power.get_hole_3())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_3())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_3())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_3())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_3())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_3())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_3())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_3())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_3())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_3())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_3())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_3())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_3())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_3())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_3())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_3())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_3())).bow_dmg_modifier;
      addAc -= -(this._l1power.getItem(power.get_hole_4())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_4())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_4())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_4())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_4())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_4())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_4())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_4())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_4())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_4())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_4())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_4())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_4())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_4())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_4())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_4())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_4())).bow_dmg_modifier;
      addAc -= -(this._l1power.getItem(power.get_hole_5())).add_ac;
      get_addstr += (this._l1power.getItem(power.get_hole_5())).add_str;
      get_adddex += (this._l1power.getItem(power.get_hole_5())).add_dex;
      get_addcon += (this._l1power.getItem(power.get_hole_5())).add_con;
      get_addwis += (this._l1power.getItem(power.get_hole_5())).add_wis;
      get_addint += (this._l1power.getItem(power.get_hole_5())).add_int;
      get_addcha += (this._l1power.getItem(power.get_hole_5())).add_cha;
      addhp += (this._l1power.getItem(power.get_hole_5())).addMaxHP;
      addmp += (this._l1power.getItem(power.get_hole_5())).addMaxMP;
      addHpr += (this._l1power.getItem(power.get_hole_5())).add_hpr;
      addMpr += (this._l1power.getItem(power.get_hole_5())).add_mpr;
      addDmgModifier += (this._l1power.getItem(power.get_hole_5())).dmg_modifier;
      addHitModifier += (this._l1power.getItem(power.get_hole_5())).hit_modifier;
      addMr += (this._l1power.getItem(power.get_hole_5())).m_def;
      addSp += (this._l1power.getItem(power.get_hole_5())).add_sp;
      bow_hit_modifier += (this._l1power.getItem(power.get_hole_5())).bow_hit_modifier;
      bow_dmg_modifier += (this._l1power.getItem(power.get_hole_5())).bow_dmg_modifier;
    } 
    if (pvp_dmg != 0)
      this._owner.addPVPdmg(-pvp_dmg); 
    if (pvp_redmg != 0)
      this._owner.addPVPdmgReduction(-pvp_redmg); 
    if (potion_heal != 0)
      this._owner.addattr_potion_heal(-potion_heal); 
    if (attr_物理格档 != 0)
      this._owner.addattr_物理格档(-attr_物理格档); 
    if (attr_魔法格档 != 0)
      this._owner.addattr_魔法格档(-attr_魔法格档); 
    if (attr_dmgR != 0)
      this._owner.addother_ReductionDmg(-attr_dmgR); 
    if (attr_hpr != 0)
      this._owner.addHpr(-attr_hpr); 
    if (attr_mpr != 0)
      this._owner.addMpr(-attr_mpr); 
    if (addhp != 0)
      this._owner.addMaxHp(-addhp); 
    if (addmp != 0)
      this._owner.addMaxMp(-addmp); 
    this._owner.addAc(addAc);
    this._owner.addBowDmgup(-bow_dmg_modifier);
    this._owner.addBowHitup(-bow_hit_modifier);
    this._owner.addDmgup(-addDmgModifier);
    this._owner.addHitup(-addHitModifier);
    this._owner.addStr((byte)-get_addstr);
    this._owner.addDex((byte)-get_adddex);
    this._owner.addCon((byte)-get_addcon);
    this._owner.addWis((byte)-get_addwis);
    if (get_addwis != 0)
      this._owner.resetBaseMr(); 
    this._owner.addInt((byte)-get_addint);
    this._owner.addCha((byte)-get_addcha);
    addMr = eq.getMr() + eq.getItemMr() + attr_def;
    if (eq.getName().equals("精灵盾牌") && this._owner.isElf())
      addMr = 5; 
    if (addMr != 0) {
      this._owner.addMr(-addMr);
      this._owner.sendPackets((ServerBasePacket)new S_SPMR(this._owner));
    } 
    addSp += eq.getSp() + eq.getItemSp();
    if (addSp != 0) {
      this._owner.addSp(-addSp);
      this._owner.sendPackets((ServerBasePacket)new S_SPMR(this._owner));
    } 
    if (addHpr != 0)
      this._owner.addHpr(-addHpr); 
    if (addMpr != 0)
      this._owner.addMpr(-addMpr); 
    if (eq.getItemistSustain() != 0)
      this._owner.addRegistSustain(-eq.getItemistSustain()); 
    if (eq.getItemistStun() != 0)
      this._owner.addRegistStun(-eq.getItemistStun()); 
    if (eq.getItemistStone() != 0)
      this._owner.addRegistStone(-eq.getItemistStone()); 
    if (eq.getItemistSleep() != 0)
      this._owner.addRegistSleep(-eq.getItemistSleep()); 
    if (eq.getItemistFreeze() != 0)
      this._owner.add_regist_freeze(-eq.getItemistFreeze()); 
    if (eq.getItemistBlind() != 0)
      this._owner.addRegistBlind(-eq.getItemistBlind()); 
    boolean isHasteItem = item.isHasteItem();
    if (isHasteItem) {
      this._owner.addHasteItemEquipped(-1);
      if (this._owner.getHasteItemEquipped() == 0) {
        this._owner.setMoveSpeed(0);
        this._owner.sendPacketsAll((ServerBasePacket)new S_SkillHaste(this._owner.getId(), 0, 0));
      } 
    } 
    switch (item.getType2()) {
      case 1:
        removeWeapon(eq);
        ItemClass.get().item_weapon(false, this._owner, eq);
        break;
      case 2:
        removeMagic(this._owner.getId(), eq);
        removeArmor(eq);
        ItemClass.get().item_armor(false, this._owner, eq);
        break;
    } 
    this._owner.setExpPoint(this._owner.getExpPoint() - item.getExpPoint());
  }
  
  private void setMagic(L1ItemInstance item) {
    switch (item.getItemId()) {
      case 402000:
      case 402001:
      case 402002:
      case 402003:
        if (!this._owner.hasSkillEffect(8010))
          this._owner.setSkillEffect(8010, 0); 
        break;
      case 402004:
      case 402005:
      case 402006:
      case 402007:
        if (!this._owner.hasSkillEffect(8020))
          this._owner.setSkillEffect(8020, 0); 
        break;
      case 20062:
      case 20077:
      case 120077:
        if (!this._owner.hasSkillEffect(60)) {
          this._owner.killSkillEffectTimer(97);
          this._owner.setSkillEffect(60, 0);
          this._owner.sendPackets((ServerBasePacket)new S_Invis(this._owner.getId(), 1));
          this._owner.broadcastPacketAll((ServerBasePacket)new S_RemoveObject((L1Object)this._owner));
        } 
        break;
      case 20288:
      case 120288:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(1, true));
        break;
      case 20281:
      case 120281:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(2, true));
        break;
      case 20284:
      case 120284:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(5, true));
        break;
      case 20383:
        if (item.getChargeCount() != 0) {
          item.setChargeCount(item.getChargeCount() - 1);
          this._owner.getInventory().updateItem(item, 128);
        } 
        if (this._owner.hasSkillEffect(1000)) {
          this._owner.killSkillEffectTimer(1000);
          this._owner.sendPacketsAll((ServerBasePacket)new S_SkillBrave(this._owner.getId(), 0, 0));
          this._owner.setBraveSpeed(0);
        } 
        break;
      case 20013:
        if (!this._owner.isSkillMastery(26))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 26)); 
        if (!this._owner.isSkillMastery(43))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 43)); 
        break;
      case 20014:
        if (!this._owner.isSkillMastery(1))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 1)); 
        if (!this._owner.isSkillMastery(19))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 19)); 
        break;
      case 20015:
        if (!this._owner.isSkillMastery(12))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 12)); 
        if (!this._owner.isSkillMastery(13))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 13)); 
        if (!this._owner.isSkillMastery(42))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 42)); 
        break;
      case 20008:
        if (!this._owner.isSkillMastery(43))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 43)); 
        break;
      case 20023:
        if (!this._owner.isSkillMastery(54))
          this._owner.sendPackets((ServerBasePacket)new S_AddSkill(this._owner, 54)); 
        break;
    } 
  }
  
  private void removeMagic(int objectId, L1ItemInstance item) {
    switch (item.getItemId()) {
      case 402000:
      case 402001:
      case 402002:
      case 402003:
        if (this._owner.hasSkillEffect(8010))
          this._owner.removeSkillEffect(8010); 
        break;
      case 402004:
      case 402005:
      case 402006:
      case 402007:
        if (this._owner.hasSkillEffect(8020))
          this._owner.removeSkillEffect(8020); 
        break;
      case 20062:
      case 20077:
      case 120077:
        this._owner.delInvis();
        break;
      case 20288:
      case 120288:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(1, false));
        break;
      case 20281:
      case 120281:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(2, false));
        break;
      case 20284:
      case 120284:
        this._owner.sendPackets((ServerBasePacket)new S_Ability(5, false));
        break;
      case 20013:
        if (!CharSkillReading.get().spellCheck(objectId, 26))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 26)); 
        if (!CharSkillReading.get().spellCheck(objectId, 43))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 43)); 
        break;
      case 20014:
        if (!CharSkillReading.get().spellCheck(objectId, 1))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 1)); 
        if (!CharSkillReading.get().spellCheck(objectId, 19))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 19)); 
        break;
      case 20015:
        if (!CharSkillReading.get().spellCheck(objectId, 12))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 12)); 
        if (!CharSkillReading.get().spellCheck(objectId, 13))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 13)); 
        if (!CharSkillReading.get().spellCheck(objectId, 42))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 42)); 
        break;
      case 20008:
        if (!CharSkillReading.get().spellCheck(objectId, 43))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 43)); 
        break;
      case 20023:
        if (!CharSkillReading.get().spellCheck(objectId, 54))
          this._owner.sendPackets((ServerBasePacket)new S_DelSkill(this._owner, 54)); 
        break;
    } 
  }
}
